 
package marker.xml.metadata;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
 
public class MsgBean {
	@Attribute
	private int code;
	@Attribute(required=false)
	private String desc;
	@Attribute
	private String module;
	@Attribute
	private String name;
	@ElementList(inline=true,name="property",required=false,type=Property.class)
	private List<Property> properties;
	
	private String returnMsg="";
	 
	private boolean request=false;
	public boolean isRequest() {
		return request;
	}
	public void setRequest(boolean request) {
		this.request = request;
	}
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public String getModule() {
		return module;
	}
	public void setModule(String module) {
		this.module = module;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getConstName(){
		return getModule().toUpperCase()+"_"+getName().toUpperCase()+"_"+(isRequest()?"REQ":"RESP");
	}
	public List<Property> getProperties() {
		if(properties==null){
			properties=new ArrayList<Property>();
		}
		return properties;
	}
	public void setProperties(List<Property> properties) {
		this.properties = properties;
	}
	
	public String getReturnMsg() {
		return returnMsg;
	}
	public void initReturnMsg(ResponsesBean responseBean){
		if(responseBean!=null){
			StringBuffer desc=new StringBuffer();
			List<ReturnMsg> success=responseBean.getSuccess();
			if(success!=null){
				desc.append("*成功返回消息：\r\n");
				for(ReturnMsg msg:success){
					desc.append("*      消息号:").append(msg.getValue()).append(" 描述:").append(msg.getDesc()).append("\r\n");
				}
			}
			List<ReturnMsg> fail=responseBean.getFail();
			if(fail!=null){
				desc.append("*失败返回消息：\r\n");
				for(ReturnMsg msg:fail){
					desc.append("*      消息号:").append(msg.getValue()).append(" 描述:").append(msg.getDesc()).append("\r\n");
				}
			}
			this.returnMsg=desc.toString();
		}
	}
 
}
